package slhs.tempo.scriptGenerator;

import java.awt.Color;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class LookAndFeelManager {

    protected static String LOOKANDFEEL = "Metal";

    void initLookAndFeel() {
	String lookAndFeel = null;

	if (LOOKANDFEEL != null) {
	    if (LOOKANDFEEL.equals("Metal")) {
		lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();

	    }

	    else if (LOOKANDFEEL.equals("System")) {
		lookAndFeel = UIManager.getSystemLookAndFeelClassName();
	    }

	    else if (LOOKANDFEEL.equals("Motif")) {
		lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
	    }

	    else if (LOOKANDFEEL.equals("GTK")) {
		lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
	    }

	    else if (LOOKANDFEEL.equals("Nimbus")) {
		lookAndFeel = "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
		UIManager.put("nimbusBlueGrey", Color.LIGHT_GRAY);
		UIManager.put("nimbusBase", Color.GRAY);
		UIManager.put("control", Color.WHITE);
	    }

	    else {
		System.err.println("Unexpected value of LOOKANDFEEL specified: " + LOOKANDFEEL);
		lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
	    }

	    try {
		UIManager.setLookAndFeel(lookAndFeel);
	    }

	    catch (ClassNotFoundException e) {
		System.err.println("Couldn't find class for specified look and feel:" + lookAndFeel);
		System.err.println("Did you include the L&F library in the class path?");
		System.err.println("Using the default look and feel.");
	    }

	    catch (UnsupportedLookAndFeelException e) {
		System.err.println("Can't use the specified look and feel (" + lookAndFeel + ") on this platform.");
		System.err.println("Using the default look and feel.");
	    }

	    catch (Exception e) {
		System.err.println("Couldn't get specified look and feel (" + lookAndFeel + "), for some reason.");
		System.err.println("Using the default look and feel.");
		e.printStackTrace();
	    }
	}
    }

    protected void setTheme(String theme) {
	LOOKANDFEEL = theme;
    }
}
